--[[
 游戏中的GameSession
使用 ：

	
]]
local GameState = require("framework.cc.utils.GameState")
local GameSession = {};


local session_ = {};

--初始化
function GameSession.new()
	local stateListener = function(event)
		if event.errorCode then
			print("ERROR, load:" .. event.errorCode)
			return
		end

		if "load" == event.name then
			local str = crypto.decryptXXTEA(event.values.data, "scertKey")
            local gameData = json.decode(str);
            session_ = gameData;
            echoj(gameData, "gameData:")
		elseif "save" == event.name then
			local str = json.encode(event.values)
            if str then
                str = crypto.encryptXXTEA(str, "scertKey")
            else
            	print("ERROR, encode fail")
                return
            end

			return {data = str}
		end
	end
	
	GameState.init(stateListener, "gameState.dat", "keyHTL")
	GameState.load()
end




--[[
 保存的seesion
]]
function GameSession.set(key,value)
	if not session_ then
		session_ = {};
	end
	
	session_[key] = value;
	
	--每次存储需要保存一次
	--GameSession.save();
end

function GameSession.get(key)
	return session_[key];
end


function GameSession.save()
	if session_ then
		GameState.save(session_)
	end
end


GameSession.new()
return GameSession;